import Vue from 'vue';
import Router from 'vue-router';
import {
  sync
} from 'vuex-router-sync';
import App from '../../App.vue';
import store from '../../store';
import '@/style/base.scss';
import KboneUI from 'kbone-ui';
import 'kbone-ui/lib/weui/weui.css';
import kboneAPI from 'kbone-api';
import moment from 'moment';
import i18n from 'i18n';
import * as Promise from "bluebird";

import CouponPage from 'mpViews/couponPage';
import CouponSearchPage from 'mpViews/couponPage/searchPage';
import MyCouponPage from 'mpViews/couponPage/myCouponPage';
import CouponTaoPage from 'mpViews/couponTaoPage';
import CouponTaoDetail from 'mpViews/couponTaoPage/couponTaoDetail';
import CouponTaoSearchPage from 'mpViews/couponTaoPage/searchPage';


Vue.use(Router);
Vue.use(KboneUI);
Vue.use(kboneAPI);

moment.locale('zh-cn');
Vue.prototype.$moment = moment;
Vue.prototype.i18n = i18n;

const router = new Router({
  mode: 'history',
  routes: [{
    path: '/couponPage',
    name: 'couponPage',
    component: CouponPage
  }, {
    path: '/couponSearchPage',
    name: 'couponSearchPage',
    component: CouponSearchPage
  }, {
    path: '/myCouponPage',
    name: 'myCouponPage',
    component: MyCouponPage
  }, {
    path: '/couponTaoPage',
    name: 'couponTaoPage',
    component: CouponTaoPage
  }, {
    path: '/couponTaoDetail/:id',
    name: 'couponTaoDetail',
    component: CouponTaoDetail
  }, {
    path: '/couponTaoSearchPage',
    name: 'couponTaoSearchPage',
    component: CouponTaoSearchPage
  }]
});

window.onShareAppMessage = function () {
  let href = window.location.href;
  let origin = window.location.origin;
  let url = href.substring(origin.length);
  return {
    path: url
  }
};

window.Promise = Promise;

export default function createApp() {
  const container = document.createElement('div')
  container.id = 'app'
  document.body.appendChild(container)

  Vue.config.productionTip = false

  sync(store, router)

  return new Vue({
    el: '#app',
    router,
    store,
    render: h => h(App)
  })
}
